Code coverage report for src/navbar/navbar.js

Statements: 95.45% (21 / 22)      Branches: 83.33% (5 / 6)      Functions: 100% (8 / 8)      Lines: 95.24% (20 / 21)      Ignored: none     

All files » src/navbar/ » navbar.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66    1       5           5 5             5   5         5 5 15       5   30       15   15   30 30 30     30   30 10   20                        
'use strict';
 
angular.module('mgcrea.ngStrap.navbar', [])
 
  .provider('$navbar', function() {
 
    var defaults = this.defaults = {
      activeClass: 'active',
      routeAttr: 'data-match-route',
      strict: false
    };
 
    this.$get = function() {
      return {defaults: defaults};
    };
 
  })
 
  .directive('bsNavbar', function($window, $location, $navbar) {
 
    var defaults = $navbar.defaults;
 
    return {
      restrict: 'A',
      link: function postLink(scope, element, attr, controller) {
 
        // Directive options
        var options = angular.copy(defaults);
        angular.forEach(Object.keys(defaults), function(key) {
          if(angular.isDefined(attr[key])) options[key] = attr[key];
        });
 
        // Watch for the $location
        scope.$watch(function() {
 
          return $location.path();
 
        }, function(newValue, oldValue) {
 
          var liElements = element[0].querySelectorAll('li[' + options.routeAttr + ']');
 
          angular.forEach(liElements, function(li) {
 
            var liElement = angular.element(li);
            var pattern = liElement.attr(options.routeAttr).replace('/', '\\/');
            Iif(options.strict) {
              pattern = '^' + pattern + '$';
            }
            var regexp = new RegExp(pattern, 'i');
 
            if(regexp.test(newValue)) {
              liElement.addClass(options.activeClass);
            } else {
              liElement.removeClass(options.activeClass);
            }
 
          });
 
        });
 
      }
 
    };
 
  });